/*
 * Copyright (c) 1994-2017, Joyoung Stock CO.LTD.
 * The FWJR Project.
 * All Rights Reserved.
 */

package com.hepinghospital.user.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;

import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.hepinghospital.user.R;

import org.jetbrains.annotations.NotNull;

import java.util.Objects;


public class BaseDialogFragment extends DialogFragment {
    protected int mScreenWidth;
    private int mScreenHeight;
    protected Activity mContext;
    //正常加载
    //onAttach -> onCreate -> onCreateView -> onActivityCreated -> onStart -> onResume
    //正常退出
    //onPause -> onStop -> onDestroyView -> onDestroyView -> onDestroy -> onDetach。

    @Override
    public void onAttach(@NotNull Context context) {
        mContext = (Activity) context;
        super.onAttach(context);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DisplayMetrics metric = new DisplayMetrics();
        requireActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
        mScreenWidth = metric.widthPixels; // 屏幕宽度（像素）
        mScreenHeight = metric.heightPixels; // 屏幕高度（像素）
        setStyle(STYLE_NORMAL, R.style.common_selected_dialog);
    }

    @Override
    public void show(FragmentManager manager, String tag) {
        show(manager.beginTransaction(), tag, true);
    }

    @Override
    public int show(@NotNull FragmentTransaction transaction, String tag) {
        return show(transaction, tag, true);
    }

    public int show(FragmentTransaction transaction, String tag, boolean allowStateLoss) {
        transaction.add(this, tag);
        return allowStateLoss ? transaction.commitAllowingStateLoss() : transaction.commit();
    }
}
